package com.edu.test;

import com.edu.bean.Student;
import com.edu.bean.Teacher;
import com.edu.controller.UserController;
import com.edu.dao.UserDao;
import com.edu.service.UserService;
import com.edu.service.impl.UserServiceImpl;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MyTest02 {

    @Test
    public void test01(){
        ApplicationContext context = new ClassPathXmlApplicationContext("app.xml");
        Object student = context.getBean("stu");
        System.out.println(student);

        UserController userController = context.getBean(UserController.class);
        userController.login();

        UserService userService = (UserService) context.getBean(UserService.class);
        userService.userLogin();

        UserDao userDao = context.getBean(UserDao.class);
        userDao.selectUser();
    }


    @Test
    public void test02(){
        ApplicationContext context = new ClassPathXmlApplicationContext("app.xml");
        Student stu1 = context.getBean(Student.class);
        Student stu2 = context.getBean(Student.class);
        System.out.println(stu1 == stu2);
    }


    @Test
    public void test03(){
        ApplicationContext context = new ClassPathXmlApplicationContext("app.xml");
        Student stu = context.getBean(Student.class);
        System.out.println(stu);
        System.out.println(stu.getBook());
    }


    @Test
    public void test04(){
        ApplicationContext context = new ClassPathXmlApplicationContext("app.xml");
        UserController userController = context.getBean(UserController.class);
        userController.login();
    }


    @Test
    public void test05(){
        ApplicationContext context = new ClassPathXmlApplicationContext("app.xml");
        UserService us = context.getBean(UserServiceImpl.class);
        us.userLogin();
    }

    @Test
    public void test06(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("app.xml");
        Teacher t = context.getBean(Teacher.class);
        System.out.println(t);
        context.close();
    }
}
